package com.xbongbong.paas.script.i18n;

import com.xbongbong.paas.toolbox.util.StringUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * 自定义LocaleResolver
 *
 * @author kaka
 * @version v1.0
 * @date 2020/5/8 14:05
 * @since v1.0
 */
@Configuration
public class XbbLocaleResolver implements LocaleResolver {

    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        String lang = request.getParameter("lang");
        if (StringUtil.isEmpty(lang)) {
            return Locale.CHINA;
        } else {
            String[] split = lang.split("_");
            return new Locale(split[0], split[1]);
        }
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {

    }
}